#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,p[100001],pc[100001],ans;
bool o1,o2,o0;
struct cr{
    int d,v,a;
    bool operator <(cr C){
        return a<C.a;
    }
}x[100001];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&t);
    for (;t;t--){
        scanf("%d%d%d%d",&n,&m,&l,&v);
        for (int i=1;i<=n;i++) scanf("%d%d%d",&x[i].d,&x[i].v,&x[i].a);
        for (int i=1;i<=m;i++) scanf("%d",&p[i]);
        sort(p+1,p+m+1);
        sort(x+1,x+n+1);
        ans=0;
        o1=o2=o0=false;
        for (int i=1;i<=n;i++){
            if (x[i].a==0&&x[i].v>v) ++ans,o0=true;
            else if (x[i].a<0&&x[i].v*1LL*x[i].v+2LL*x[i].a*p[1]>v*1LL*v) ++ans,o1=true;
            else if (x[i].v*1LL*x[i].v+2LL*x[i].a*p[m]>v*1LL*v) ++ans,o2=true;
        }
        int spe=o1+o2;
        if (spe==0&&o0) spe=1;
        spe=min(spe,n);
        printf("%d %d\n",ans,m-spe);
    }
    return 0;
}
